<?php   
  
  
class YoukuVideo  
{  
        var $url;   
        var $content;  
        var $videoswfstr;  
        var $playhtmlstr;  
        var $picurl;  
        var $err;  
        function show()  
        {  
            echo $this->url;  
            //echo $this->content;  
            echo $this->videoswfstr;  
            echo $this->playhtmlstr;  
            echo $this->picurl;  
        }  
        function __construct($u)  
        {              
            $this->url = $u;                      
            $this->err=0;              
            $this->run();              
        }  
          
        function getcontent()  
        {                  
                $co =  @file_get_contents($this->url);   
                if(!$co) $err=true;  
                $this->content = $co;  
        }  
        function getsubstr($posstart,$posend)  
        {  
            $len1 = strpos($this->content,$posstart);  
            $len2 = strpos($this->content,$posend,$len1);  
            $retstr =  @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart));  
            if(strlen($retstr )) return $retstr ;  
            else $err=1;  
        }  
        function youku_swf( ) //获取优酷的播放swf地址  
        {   
            $posstart = 'id="link2" value="';  
            $posend = '" >';  
            $len1 = strpos($this->content,$posstart);  
            $len2 = strpos($this->content,$posend,$len1);  
            $retstr =  substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart));  
            if(strstr($retstr,"swf"))$this->videoswfstr = $retstr;  
            else {  
                $this->err=1;$this->videoswfstr="";  
            }  
        }  
        function youku_playhtml() //获取优酷的播发界面  
        {  
            $this->playhtmlstr = @sprintf('<embed src="%s" allowFullScreen="true" quality="high" width="480" height="400" align="middle" allowScriptAccess="always"   type="application/x-shockwave-flash"></embed>',$this->videoswfstr);  
        }  
        function youku_thumb()//获取优酷视频的截图（只能返回小图的地址）  
        {  
            $posstart = "&screenshot=";  
            $posend = '" target="_blank"';  
            $len1 = strpos($this->content,$posstart);  
            $len2 = strpos($this->content,$posend,$len1);  
            $retstr =  @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart));  
            if(!$retstr) $err=1;  
            $this->picurl =  $retstr;  
        }  
        function youku_gettitle()  
        {  
            $posstart = '<meta name="title" content="';  
            $posend = '">';  
            $len1 = strpos($this->content,$posstart);  
            $len2 = strpos($this->content,$posend,$len1);  
            $retstr =  @substr($this->content,$len1+strlen($posstart),$len2 - $len1- strlen($posstart));  
            if(!$retstr) $err=1;  
            $this->title =  $retstr;  
        }  
        function run()  
        {              
            $this->getcontent();              
            $this->youku_swf();                
            $this->youku_playhtml();              
            $this->youku_thumb();              
            $this->youku_gettitle();              
            //$this->show();  
        }  
} 

?>